package com.hyq.learn.api.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.context.event.SimpleApplicationEventMulticaster;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * ApplicationEventMulticaster配置，可用于决定事件发布机制是否需要启用线程池；
 *
 * @author heyuqin
 * @date 2025/8/27 17:56
 */
@Configuration
public class EventMulticasterConfig {

    @Bean
    public ApplicationEventMulticaster applicationEventMulticaster(@Qualifier("threadPoolTaskExecutor") ThreadPoolTaskExecutor threadPoolTaskExecutor) {
        SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster();
        eventMulticaster.setTaskExecutor(threadPoolTaskExecutor);
        return eventMulticaster;
    }
}
